//-------------------------------------------------------------------
//	Copyright (c) 2012-2014 Zhirnov Andrey
//	This file is part of the "UXGEN-ES" project.
//	See copyright notice in "Engine.h".
//-------------------------------------------------------------------
/*
	Panel - widget for custom draw operation.
*/

#pragma once

#include "UI/Widgets/Widget.h"

namespace Engine
{
namespace UI
{

	class Panel;
	SHARED_POINTER( Panel );


	//
	// Panel
	//

	class Panel : public Widget
	{
		friend struct ::MetaData::PanelCfg;

	// variables
	protected:
		UIAction		_onDraw;
		UIAction		_onUpdate;


	// methods
	public:
		Panel (EWidget::type wgtType, const EngineSubSystemsRef ess);
		~Panel ();
		
		virtual bool ProcessMessage (const WidgetMsg &msg) override;

		
		static PanelPtr	New (const EngineSubSystemsRef ess);


	protected:
		bool _Update (const WidgetMsg &msg);
		bool _Draw (const WidgetMsg &msg);
	};


	
/*
=================================================
	constructor
=================================================
*/
	inline Panel::Panel (EWidget::type wgtType, const EngineSubSystemsRef ess) :
		Widget( wgtType, ess )
	{
	}
		
/*
=================================================
	destructor
=================================================
*/
	inline Panel::~Panel ()
	{
	}
		
/*
=================================================
	ProcessMessage
=================================================
*/
	inline bool Panel::ProcessMessage (const WidgetMsg &msg)
	{
		typedef WidgetMsg	WM;

		switch ( msg.GetType() )
		{
			case WM::UPDATE  :	return _Update( msg );
			case WM::DRAW :		return _Draw( msg );
		}

		return Widget::ProcessMessage( msg );
	}
		
/*
=================================================
	New
=================================================
*/
	inline PanelPtr  Panel::New (const EngineSubSystemsRef ess)
	{
		return BaseObject::_New( new Panel( EWidget::PANEL, ess ) );
	}

/*
=================================================
	_Update
=================================================
*/
	inline bool Panel::_Update (const WidgetMsg &msg)
	{
		if ( not IsVisible() )
			return true;

		_onUpdate.Call( this );

		return Widget::_Update( msg );
	}
	
/*
=================================================
	_Draw
----
	Warning: need to call Screen.Redraw() if
	need to redraw to next frame
=================================================
*/
	inline bool Panel::_Draw (const WidgetMsg &msg)
	{
		if ( not IsVisible() )
			return true;

		_onDraw.Call( this );
		
		_SendToAllAttached( msg );
		return true;
	}


}	// UI
}	// Engine